package com.springcloudserver.controller;

import com.springcloudserver.common.AjaxResult;
import com.springcloudserver.domain.UserInfo;
import com.springcloudserver.service.FeiginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: chenzuolin
 * @time: 2021/3/17 21:04
 */
@RestController
@RequestMapping("/consume")
public class HiController {

    @Autowired
    private FeiginService feiginService;

    @GetMapping("/msg")
    public AjaxResult hi() {
        return AjaxResult.success(feiginService.hi());
    }

    @GetMapping("/findById/{id}")
    @Cacheable(cacheNames = "findUserInfoById", keyGenerator = "myKeyGenerator", condition = "#id != null", sync = true)
    public AjaxResult findUserInfoById(@PathVariable("id") String id) {
        System.out.println("================" + id);
        AjaxResult userInfoById = feiginService.findUserInfoById(id);
        return AjaxResult.success(userInfoById);
    }

    @GetMapping("/findAll")
    @Cacheable(cacheNames = "findAllUserInfo", keyGenerator = "myKeyGenerator", sync = true)
    public AjaxResult findAllUserInfo() {
        AjaxResult allUserInfo = feiginService.findAllUserInfo();
        return AjaxResult.success(allUserInfo);
    }
}
